package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.entity.NursingLevel;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description NursingLevelController
 * @Author Wen Jie
 * @Date 2024-09-09
 */
@RestController
@RequestMapping("/nursingLevel")
@Api("护理计划模块")
public class NursingLevelController extends BaseController{
    @Autowired
    private NursingLevelService nursingLevelService;
    @ApiOperation("查看所有护理等级")
    @GetMapping("/listAll")
    public ResponseResult<List<NursingLevelVo>> listAll(){
        List<NursingLevelVo> nursingLevelVos = nursingLevelService.listAll();
        return success(nursingLevelVos);
    }

    @ApiOperation("条件分页查询")
    @GetMapping("/listByPage")
    public ResponseResult<PageResponse<NursingLevelVo>> listByPage(
            @ApiParam(value = "护理等级名称") @RequestParam(value = "name",required = false) String name,
            @ApiParam(value = "护理等级状态") @RequestParam(value = "status",required = false) String status,
            @ApiParam(value = "当前页码") @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页大小") @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize
    ){
        PageResponse<NursingLevelVo> nursingLevelVoPageResponse = nursingLevelService.listByPage(name,status,pageNum,pageSize);
        return success(nursingLevelVoPageResponse);
    }

    @PostMapping("/insert")
    @ApiOperation("添加护理等级名称")
    public ResponseResult addNursingLevel(
            @ApiParam(value = "护理等级信息",required = true)
            @RequestBody NursingLevelVo nursingLevelVo){
        nursingLevelService.addNursingLevel(nursingLevelVo);
        return success();
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询护理等级")
    public ResponseResult<NursingLevelVo> getById(@PathVariable("id") Long id){
        NursingLevelVo nursingLevelVo = nursingLevelService.getById(id);
        return success(nursingLevelVo);
    }

    @PutMapping("/update")
    @ApiOperation("修改护理等级")
    public ResponseResult updateNursingLevel(
            @ApiParam(value = "护理等级信息",required = true)
            @RequestBody NursingLevelVo nursingLevelVo){
        nursingLevelService.updateNursingLevel(nursingLevelVo);
        return success();
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation("根据id删除护理等级")
    public ResponseResult deleteById(@PathVariable("id") Long id){
        nursingLevelService.deleteById(id);
        return success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation("修改护理等级状态")
    public ResponseResult updateStatusById(
            @ApiParam("护理等级id") @PathVariable(value = "id",required = true) Long id,
            @ApiParam("护理等级状态") @PathVariable(value = "status",required = true) Integer status
    ){
        nursingLevelService.updateStatusById(id,status);
        return success();
    }
}
